<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <FilterTable
      ref="table"
      columnsRef="testindex"
      :columns="columns"
      :fetchapi="fetchApi"
      :isSelectColumn="false"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectData"
      :isExportExcel2="true"
      exportFileName="交货单明细.xlsx"
    >

      <!-- <template slot="controls">
        <el-button size="small" type="primary"  @click="exportClick">导出</el-button>
      </template> -->
    </FilterTable>

    <Drawer
      :visible.sync="visibleDrawer"
      title="配件发运单详情"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <info-model v-model="initData" @close="infoClose" />
    </Drawer>

    <!-- <BaseDialog title="服务商查询" :visible.sync="isShowSearchCustomer" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ownerSeacher :customerNo="kehuxuanze" @close="isShowSearchCustomer = false" @addCustomerCode="confirmSearchCustomer" />
    </BaseDialog> -->

    <BaseDialog
      :visible.sync="issearch"
      :title="'服务商查询'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <ownerSeacher  @close="dealercloseHandler" />
    </BaseDialog>
  </div>
</template>

<script>
// import ownerSeacher from './ownerSeacher';
import infoModel from './info';
import { dictionary } from '@/utils/dictMixin';
import { getShipmentData,exporturl} from '@/api/partsmanage/shipment/query';
import { banWord } from '@/utils/validate';
import ownerSeacher from '@/pages/partsmanage/claim/approve/ownerSeacher';
export default {
  name: 'shipmentqueryindex',
  mixins: [dictionary],
  components: {
    infoModel,
    ownerSeacher
  },
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      fetchParams: { xhrAbort: true },
      columns: this.createTableColumns(),
      fetchApi: getShipmentData,
      visibleDrawer: false,
      kehuxuanze: '',
      isShowSearchCustomer: false,
      issearch: false,
      dealerCode: '',
      initData: {}
    }
  },
  mounted() {
    // 分页
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
      dealercloseHandler(val){
        if(val){
          this.topFilterList.find(x=>x.fieldName=='dealerCode').initialValue=val.dealerCode;
          this.topFilterList.find(x=>x.fieldName=='dealerName').initialValue=val.dealerShortname;
        }
        this.issearch=false;
      },
    createTopFilterList() {
      return [
        {
            type: 'INPUT',
            label: '服务商代码',
            fieldName: 'dealerCode',
            placeholder: '请选择',
            unitRender: () => {
              return (
                <div>
                  <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
                </div>
              );
            }
          },
          {
            type: 'INPUT',
            label: '服务商简称',
            fieldName: 'dealerName',
            placeholder: '请输入',
          },
        {
          type: 'INPUT',
          label: '备件订单号:',
          fieldName: 'bsddwj',
          rules: [{validator: banWord, trigger: 'blur' },{max: 20, message: '长度在20个字符以内', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: '销售单号:',
          fieldName: 'hxddhm',
          hidden:true
        },
        {
          type: 'INPUT',
          label: '交货单号:',
          fieldName: 'bsysdh',
          rules: [{validator: banWord, trigger: 'blur' },{max: 20, message: '长度在20个字符以内', trigger: 'blur' }],
        },
        {
          type: 'SELECT',
          label: '开票状态',
          fieldName: 'invoiceStatus',
          itemList: this.createDictList('3051')
        },
        {
          type: 'INPUT',
          label: '备件代码:',
          fieldName: 'bjxmbh',
          hidden:true
        },
        {
          type: 'INPUT',
          label: '备件名称:',
          fieldName: 'bjzwmc',
          hidden:true
        },
        {
          type: 'RANGE_DATE',
          label: '发运日期',
          initialValue: '',
          fieldName: 'startTime|endTime',
          valueFormat: 'yyyy-MM-dd',
          placeholder: '请选择'
        },
        {
          type: 'RANGE_DATE',
          label: '签收日期',
          initialValue: '',
          fieldName: 'startTo|endTo',
          valueFormat: 'yyyy-MM-dd',
          placeholder: '请选择'
        },
        {
          type: 'SELECT',
          label: '交货单来源',
          fieldName: 'zjhdly',
          itemList: this.createDictList('3056')
        },
      ]
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button  size="mini" type="text" onClick={() => this.detailHandle(props.row, 'show')}>
                  明细
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '服务商代码',
          dataIndex: 'dealerCode',
          sorter: true,
        },
        {
          title: '服务商名称',
          dataIndex: 'dealerName',
          sorter: true,
          width: 200
        },
        {
          title: '备件订单号',
          dataIndex: 'bscsdj',
          sorter: true,
          width: 185
        },
        {
          title: '销售单号',
          dataIndex: 'bsjhdh',
          sorter: true,
          width: 180,
          hidden:true
        },
        {
          title: '交货单号',
          dataIndex: 'bsysdh',
          sorter: true,
        },
        {
          title: '交货单来源',
          dataIndex: 'zjhdly',
          sorter: true,
          dictItems: this.createDictList('3056')
        },
        {
          title: '发运方式',
          dataIndex: 'btyslx',
          sorter: true,
          filterItems: this.createDictList('3024'),
          dictItems: this.createDictList('3024'),
          filterType: 'checkbox'
        },
        {
          title: '出库日期',
          dataIndex: 'bsfyrq2',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          sorter: true,
        },
        {
          title: '签收日期',
          dataIndex: 'bsqcrq2',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          sorter: true,
          width: 180
        },
        {
          title: '预计到货日期',
          dataIndex: 'bsyjdd2',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
        },
        {
          title: '出库总数量',
          dataIndex: 'bsfysl',
          sorter: true,
        },
        {
          title: '出库总金额',
          dataIndex: 'bsamount',
          sorter: true,
          precision: 2,
          numberFormat: true
        },
        {
          title: '签收数量',
          dataIndex: 'qssl',
          sorter: true,
        },
        {
          title: '签收状态',
          dataIndex: 'xsdjzt',
          sorter: true,
          filterItems: this.createDictList('3014'),
          dictItems: this.createDictList('3014'),
        },
        {
          title: '开票状态',
          dataIndex: 'invoiceStatus',
          sorter: true,
          dictItems:this.createDictList('3051')
        },
        {
          title: '物流公司',
          dataIndex: 'wsName',
          sorter: true,
          hidden:true
        }
      ]
    },
    changeHandle(val) {
      // this.fetchParams = Object.assign({}, val);
      val.endTime && (val.endTime = val.endTime.split(' ')[0] + ' 23:59:59');
      this.fetchParams = Object.assign({},val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    selectData(val) {
      this.tableData = val;
    },
    async exportClick() {
      let json = Object.assign({}, { CODE: 'CODE_00000268' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }
    },
    detailHandle(row, type) {
      this.initData =  {
        type: type,
        data: row,
        id:1001
      }; //行id
      this.visibleDrawer = true;
    },
    infoClose(rData) {
      this.visibleDrawer = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    async confirmSearchCustomer(row) {
      console.log(row, 'rowCustomer');
      this.rowData = row[0];
      console.log('row[0].dealerCode', row[0].dealerCode);
      this.topFilterList.find(x => x.fieldName == 'ownerCode').initialValue = row[0].dealerCode;
      this.topFilterList.find(x => x.fieldName == 'ownerName').initialValue = row[0].dealerShortname;
    },
    seacherFun(){
      this.issearch=true;
    }
  }
}
</script>
